home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / startAttrPreset.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  10.9 KB  |  343 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Alias|Wavefront Script File
  19. //  MODIFY THIS AT YOUR OWN RISK
  20. //
  21. //
  22. //  Creation Date:  2001 
  23. //  Author:         dbrins 
  24. //
  25.  
  26.  
  27. global string    $gAEAttrPresetCurrentTarget;
  28. global float    $gAEAttrPresetBlend;
  29. global string    $gAEAttrPresetCopyObj = "";
  30. global string    $gAEAttrPresetSelList[];
  31. global int        $gAEAttrPresetValidNotes;
  32. global string    $gAEAttrPresetExcludeAttrs[] = {
  33.     // for now simply reject doubleSided: bug159621
  34.     // Eventually this could check for membership in attribute
  35.     // groupings for selective loading of attributes
  36.     "doubleSided",
  37.     "rotateQuaternionX",
  38.     "rotateQuaternionY",
  39.     "rotateQuaternionZ",
  40.     "rotateQuaternionW",
  41.     "outStippleThreshold",
  42.     "face",
  43.     "boundary",
  44.     "currentDisplayLayer",
  45.     "useComponentPivot",
  46.     "currentRenderLayer",    // layer needs to exist
  47.     "springStiffness",
  48.     "springDamping",
  49.     "springRestLength",
  50.     "caching",
  51.     "nodeState"
  52. };
  53. global string    $gAEAttrPresetExcludeNodeAttrs[] = {
  54.     "timeToUnitConversion.output",    // should be output-only
  55.     "unitToTimeConversion.output",
  56.     "oceanShader.outFoam",
  57.     "solidNoise.outColorR",
  58.     "solidNoise.outColorG",
  59.     "solidNoise.outColorB",
  60.     "solidNoise.outAlpha",
  61.     "joint.rotatePivotX",            // normalised, so they affect one another
  62.     "joint.rotatePivotY",
  63.     "joint.rotatePivotZ",
  64.     "samplerInfo.normalCameraX",    // normalised, so they affect one another
  65.     "samplerInfo.normalCameraY",
  66.     "samplerInfo.normalCameraZ",
  67.     "samplerInfo.rayDirectionX",    // normalised, so they affect one another
  68.     "samplerInfo.rayDirectionY",
  69.     "samplerInfo.rayDirectionZ",
  70.     "airField.maxDistance",        // can be set below their minimum value by presets
  71.     "dragField.maxDistance",
  72.     "gravityField.maxDistance",
  73.     "newtonField.maxDistance",
  74.     "radialField.maxDistance",
  75.     "turbulenceField.maxDistance",
  76.     "uniformField.maxDistance",
  77.     "volumeAxisField.maxDistance",
  78.     "vortexField.maxDistance",
  79.     "torusField.maxDistance",
  80.     "FurFeedback.realUSamples",    // dynamic/internal, affected by other attributes
  81.     "FurFeedback.realVSamples",
  82.     "globalStitch.updateSampling", // reset by the 'sampling' attribute
  83.     "fluidShape.controlPoints.xValue",
  84.     "fluidShape.controlPoints.yValue",
  85.     "fluidShape.controlPoints.zValue",
  86.     "fluidShape.weights",
  87.     "fluidShape.seed"
  88. };
  89.  
  90. // Decide which parameters we will use from the current preset.  
  91. // If the attribute is in the excluded attrs list above, or 
  92. // the type.attr string is in the excluded node.attrs list above,
  93. // this attribute will neither be SAVED to a preset file *or*
  94. // READ back in from a preset file.
  95. // 
  96. global proc int validNodeTypeAttrForCurrentPreset( string $type, 
  97.                                                    string $attr ) 
  98. {
  99.     global string $gAEAttrPresetExcludeAttrs[];
  100.     global string $gAEAttrPresetExcludeNodeAttrs[];
  101.  
  102.     string $oldAttr = "";
  103.     int    $i;
  104.  
  105.     // For the purposes of matching the above string
  106.     // arrays, we should strip off any multi indexing
  107.     // from the attr names.  Paranoia of a pathological
  108.     // test case causing an infinite loop means we're
  109.     // capping the multi parent hierarchy at 10 levels...
  110.     //
  111.     for( $i = 0; $oldAttr != $attr && $i < 10; $i++ ) {
  112.         // This is our loop control.
  113.         //
  114.         $oldAttr = $attr;
  115.  
  116.         // For the following example: parent[1].child[2].x
  117.         // we'd loop through three times with these results
  118.         // after each execution of the following substitution.
  119.         // 
  120.         //     1) $oldAttr = parent[1].child[2].x
  121.         //     $attr    = parent.child[2].x
  122.         //     2) $oldAttr = parent.child[2].x
  123.         //     $attr    = parent.child.x
  124.         //     3) $oldAttr = parent.child.x
  125.         //     $attr    = parent.child.x
  126.         // 
  127.         $attr = substitute( "\\[[0-9]*\\]", $attr, "" );
  128.     } 
  129.  
  130.     // Check attributes regardless of node type.
  131.     //
  132.     if (stringArrayCount($attr, $gAEAttrPresetExcludeAttrs) > 0) {
  133.         return 0;
  134.     }
  135.  
  136.     // Check attributes with specific node types.
  137.     //
  138.     string $excludeNodeAttr = $type + "." + $attr;
  139.     if (stringArrayCount($excludeNodeAttr, $gAEAttrPresetExcludeNodeAttrs) > 0) {
  140.         return 0;
  141.     }
  142.  
  143.     return 1;
  144. }
  145.  
  146. global proc int validAttrForCurrentPreset( string $attr ) {
  147.     global string $gAEAttrPresetCurrentTarget;
  148.     string $type = `nodeType $gAEAttrPresetCurrentTarget`;
  149.  
  150.     return validNodeTypeAttrForCurrentPreset( $type, $attr );
  151. }
  152.  
  153. //
  154. //  handle string preset values  
  155. //
  156. global proc blendAttrStr( string $attr, string $str )
  157. {
  158.     global string $gAEAttrPresetCurrentTarget;
  159.     global float    $gAEAttrPresetBlend;
  160.     global int $gAEAttrPresetValidNotes;
  161.     if( $gAEAttrPresetBlend > 0.5 ){
  162.         if( size($gAEAttrPresetCurrentTarget) > 0){
  163.             if( validAttrForCurrentPreset( $attr ) ){
  164.                 string $objAttr = $gAEAttrPresetCurrentTarget + "." + $attr;
  165.                 if($attr == "notes" || $attr == "nts") {
  166.                     $gAEAttrPresetValidNotes = 1;
  167.                     // we know what kind of dynamic attr notes has to be
  168.                     // so we can create it. A blatant special case if we ever saw one
  169.                     // in future we should write out a blendDynAttr command which
  170.                     // specifies the type info for dynamic attributes to be created
  171.                     if(!objExists( $objAttr )) {
  172.                         if( catch(`addAttr -dt "string" -ln "notes" -sn "nts"  $gAEAttrPresetCurrentTarget`)) {
  173.                             error(" Could not create dynamic attribute: " + $objAttr);
  174.                         }
  175.                     }
  176.                 }
  177.                 if(objExists( $objAttr ) && `getAttr -settable $objAttr`) {
  178.                     setAttr -type "string" $objAttr $str;
  179.                 }
  180.             }
  181.         }
  182.     }
  183. }
  184.  
  185. //
  186. //  handle scalar preset values  
  187. //
  188. global proc blendAttr( string $attr, float $val )
  189. {
  190.     global string $gAEAttrPresetCurrentTarget;
  191.     global float    $gAEAttrPresetBlend;
  192.     global string    $gAEAttrPresetCopyObj;
  193.  
  194. // print ("setting Attr " + $attr + "\n" );
  195.     if( size($gAEAttrPresetCurrentTarget) > 0){
  196.         if( validAttrForCurrentPreset( $attr ) ){
  197.             string $objAttr = $gAEAttrPresetCurrentTarget + "." + $attr;
  198.             if( `getAttr -se $objAttr`) {
  199.                 if( $gAEAttrPresetBlend < 0.999 ){
  200.                         $targAttr = $gAEAttrPresetCopyObj + "." + $attr;
  201.                         if( objExists( $targAttr ) ){
  202.                             string $attrType = `getAttr -type $targAttr`;
  203.                             switch ($attrType) {
  204.                                 case "enum":
  205.                                     if( $gAEAttrPresetBlend < 0.5 ){
  206.                                         $val = getAttr( $targAttr );
  207.                                     }
  208.                                     setAttr ($gAEAttrPresetCurrentTarget + "." + $attr) $val;
  209.                                     break;
  210.                                 case "bool":
  211.                                 case "short":
  212.                                 case "long":
  213.                                 case "byte":
  214.                                 case "char":
  215.                                     int $intVal = (int)($val * $gAEAttrPresetBlend 
  216.                                         + getAttr($targAttr) * (1-$gAEAttrPresetBlend));
  217.                                     setAttr ($gAEAttrPresetCurrentTarget + "." + $attr) $intVal;
  218.                                     break;
  219.  
  220.                                 // These cases are expected in default
  221.                                 //
  222.                                 //    case "float":
  223.                                 //    case "floatLinear":
  224.                                 //    case "double":
  225.                                 //    case "doubleLinear":
  226.                                 //    case "doubleAngle":
  227.                                 //    case "time":
  228.                                 //
  229.                                 default:
  230.                                     $val = $val * $gAEAttrPresetBlend 
  231.                                         + getAttr($targAttr) * (1-$gAEAttrPresetBlend);
  232.                                     setAttr -c ($gAEAttrPresetCurrentTarget + "." + $attr) $val;
  233.                                     break;
  234.                             }
  235.                         }
  236.                 } else {
  237.                     setAttr -c $objAttr $val;
  238.                 }
  239.             }
  240.         }
  241.     }
  242. }
  243.  
  244. //
  245. // Clean up after setting preset values
  246. //
  247. global proc endAttrPreset()
  248. {
  249. // print ("endAttrPreset\n" );
  250.     global float    $gAEAttrPresetBlend;
  251.     global string    $gAEAttrPresetCopyObj;
  252.     global string    $gAEAttrPresetSelList[];
  253.  
  254.     global string $gAEAttrPresetCurrentTarget;
  255.     global int $gAEAttrPresetValidNotes;
  256.  
  257.     // if we didn't find any notes in the preset, and the node has
  258.     // ols out of date notes, remove them
  259.     if($gAEAttrPresetValidNotes == 0) {
  260.         string $notesAttr =  $gAEAttrPresetCurrentTarget + ".notes";
  261.         if(objExists( $notesAttr )) {
  262.             if( catch(`deleteAttr -at "notes" $gAEAttrPresetCurrentTarget`)) {
  263.                 error(" Could not delete dynamic attribute: " + $notesAttr);
  264.             }
  265.         }
  266.     }
  267.     $gAEAttrPresetCopyObj = "";
  268.     $gAEAttrPresetSelList = {};
  269. }
  270.  
  271. //
  272. // Initialize for preset calls
  273. //
  274. global proc startAttrPreset( string $nodeType )
  275. {
  276.     global string $gAEAttrPresetCurrentTarget;
  277.     global float    $gAEAttrPresetBlend;
  278.     global string    $gAEAttrPresetSelList[];
  279.     global string    $gAEAttrPresetCopyObj;
  280.     global int      $gAEAttrPresetValidNotes;
  281.  
  282.     $gAEAttrPresetValidNotes = 1;
  283.     if( objExists( $gAEAttrPresetCurrentTarget ) ){
  284.         string $type = nodeType($gAEAttrPresetCurrentTarget);
  285.         if( $type != $nodeType ){
  286.             warning( "Preset type" + $nodeType + " does not match current selection." );
  287.             $gAEAttrPresetCurrentTarget = "";
  288.         } else {
  289.             $gAEAttrPresetCopyObj = $gAEAttrPresetCurrentTarget;
  290.  
  291.             if( $gAEAttrPresetBlend > 0.5 ){
  292.                 // mark current notes as invalid
  293.                 // we can delete the attr later if we don't get new notes from the preset
  294.                 $gAEAttrPresetValidNotes = 0;
  295.             }
  296.  
  297.             if( $gAEAttrPresetBlend > 0.7 ){ 
  298.                 // Delete relevant multi entries
  299.                 string $multies[] = `attributeInfo -m 1 -and -w 1 -and -h 0 $gAEAttrPresetCurrentTarget`;
  300.                 string $mult;
  301.                 for ($mult in $multies ){
  302.                     string $nodeName = $gAEAttrPresetCurrentTarget +"."+$mult;
  303.                     if( objExists( $nodeName ) ){
  304.                         int $i, $size;
  305.                         string $entries[] = `listAttr -m -st $mult $gAEAttrPresetCurrentTarget`;
  306.                         $size = size($entries);
  307.                         // do this in reverse order because the widget wants to
  308.                         // reconnect to the lowest index when its attr is deleted out
  309.                         // from under it, so we don't want it to keep reconnecting all the time
  310.                         for( $i = $size -1; $i >= 0; $i-- ){
  311.                             string $multiName = $gAEAttrPresetCurrentTarget + "." + $entries[$i];
  312.                             string $atrs[] = `listAttr -s $multiName`;
  313.                             int $doDelete = 1;
  314.                             if( size( $atrs ) > 0 ){
  315.                                 for ($atr in $atrs) 
  316.                                 {
  317.                                     string $attrName = $gAEAttrPresetCurrentTarget + "." + $atr;
  318.                                     if( !objExists( $attrName )
  319.                                     || `connectionInfo -id $attrName`
  320.                                     || `connectionInfo -is $attrName`
  321.                                      || `connectionInfo -il $attrName`){
  322.                                     // only delete if no children are connected or
  323.                                     // locked
  324.                                         $doDelete = 0;
  325.                                         break;
  326.                                     }
  327.                                 }
  328.                             } else {
  329.                                 $doDelete = 0;
  330.                             }
  331.                             if( $doDelete ){
  332.                                 removeMultiInstance $multiName;    
  333.                             } 
  334.                         }
  335.                     }
  336.                 }
  337.             }
  338.         }
  339.     } else {
  340.         $gAEAttrPresetCurrentTarget = "";
  341.     }
  342. }
  343.